Adding some more judges, here and there.
[and.git] / Maratones competidas / Maratón Nacional 2011 / workspace / g / gas.cpp
blob551f2ead5afd8dc0e87ae54cbdc18f29efed7fed
1 // Equipo Poncho, Carriel y Ruana
2 using namespace std;
3 #include <algorithm>
4 #include <iostream>
5 #include <iterator>
6 #include <sstream>
7 #include <fstream>
8 #include <cassert>
9 #include <climits>
10 #include <cstdlib>
11 #include <cstring>
12 #include <string>
13 #include <cstdio>
14 #include <vector>
15 #include <cmath>
16 #include <queue>
17 #include <stack>
18 #include <list>
19 #include <map>
20 #include <set>
22 template <class T> string toStr(const T &x)
23 { stringstream s; s << x; return s.str(); }
24 template <class T> int toInt(const T &x)
25 { stringstream s; s << x; int r; s >> r; return r; }
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
28 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
29 #define D(x) cout << #x " = " << (x) << endl;
31 const double EPS = 1e-9;
33 int cmp(double x, double y = 0, double tol = EPS) {
34 return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
37 #define INPUT_FILE "gas"
40 int main(){
41 freopen(INPUT_FILE ".in", "r", stdin);
42 long long l, gases;
44 vector< pair<long long, long long> > stations;
46 while(cin >> l >> gases) {
47 bool found = true;
48 stations.clear();
49 if(l == 0 and gases == 0) break;
50 for(long long i=0; i<gases; i++) {
51 long long p, r;
52 long long zero = 0;
53 cin >> p >> r;
54 long long li, ls;
55 li = max(zero, p-r);
56 ls = min(l, p+r);
57 stations.push_back(make_pair(li, ls));
59 sort(stations.begin(), stations.end());
60 long long last_index = 0;
61 long long usados = 0;
62 for(long long i = 0; i<l;) {
63 long long fin = i;
64 bool primero = true;
65 for(long long g = last_index; g<stations.size(); ++g) {
66 if (stations[g].first <= i and stations[g].second > i) {
67 if (primero) {
68 primero = false;
69 last_index = g;
71 fin = max(fin, stations[g].second);
73 if (stations[g].first > i) break;
75 if(i == fin) {
76 cout << -1 << endl;
77 found = false;
78 break;
80 i = fin;
81 usados++;
83 if (found) cout << gases-usados << endl;
86 return 0;